package com.csii.adhoc.dataunits.mapper;

import com.csii.adhoc.dblink.DbLinkPo;
import com.csii.common.DataFromVo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public interface DataUnitsMapper {

    @Select(value = "${paramSql}")
    @ResultType(LinkedHashMap.class)
    List<Map<String, Object>> generalSqlQuery(@Param("paramSql") String sql);

    @Select("select * from t_data_from where table_id = #{tableId}")
    @Results(value = {
            @Result(id = true, column = "TABLE_ID", property = "tableId"),
            @Result(column = "CONN_ID", property = "connId"),
            @Result(column = "TABLE_NAME", property = "tableName"),
            @Result(column = "ALIAS", property = "alias"),
            @Result(column = "TABLE_CNNAME", property = "tableCnname"),
            @Result(column = "TABLE_SHOWNAME", property = "tableShowname"),
            @Result(column = "SRC_TYPE", property = "srcType"),
            @Result(column = "SRC_LAYER", property = "srcLayer"),
            @Result(column = "SRC_SUBJECT", property = "srcSubject"),
            @Result(column = "SRC_TABLE", property = "srcTable"),
    })
    DataFromVo getConnIdByTableId(@Param("tableId") String tableId);


    @Select("select * from T_MGN_DB")
    @Results(value = {
            @Result(id = true, column = "CONN_ID", property = "connId"),
            @Result(column = "NAME", property = "name"),
            @Result(column = "ABBR_NAME", property = "abbrName"),
            @Result(column = "IP", property = "ip"),
            @Result(column = "HOST", property = "host"),
            @Result(column = "PORT", jdbcType = JdbcType.INTEGER, javaType = BigDecimal.class, property = "port"),
            @Result(column = "DBNAME", property = "dbname"),
            @Result(column = "TYPE", property = "type"),
            @Result(column = "USERNAME", property = "username"),
            @Result(column = "PASSWD", property = "passwd"),
            @Result(column = "OWNER", property = "owner"),
            @Result(column = "VERSION", property = "version"),
            @Result(column = "DRIVER_CLASS", property = "driverClass"),
            @Result(column = "DBTYPE", property = "dbtype"),
            @Result(column = "DECODE", property = "decode"),
            @Result(column = "URL", property = "url"),
            @Result(column = "INITIAL_SIZE", property = "initialSize"),
            @Result(column = "MINIDLE", property = "minidle"),
            @Result(column = "MAX_ACTIVE", property = "maxActive"),
            @Result(column = "MAX_WAIT", property = "maxWait"),
            @Result(column = "TIME_RUNS_MILLIS", property = "timeRunsMillis"),
            @Result(column = "MIN_TIME_MILLIS", property = "minTimeMillis"),
            @Result(column = "VALIDATION_QUERY", property = "validationQuery"),
            @Result(column = "TEST_WHILE_IDLE", property = "testWhileIdle"),
            @Result(column = "TEST_ON_BORROW", property = "testOnBorrow"),
            @Result(column = "TEST_ON_RETURN", property = "testOnReturn"),
            @Result(column = "POOL_PREPARED_STATEMENTS", property = "poolPreparedStatements"),
            @Result(column = "MAX_CONNECTION_SIZE", property = "maxConnectionSize"),
            @Result(column = "FILTERS", property = "filters"),
            @Result(column = "CREATED_BY", property = "createdBy"),
            @Result(column = "CREATED_DT", property = "createdDt"),
            @Result(column = "UPDATED_BY", property = "updatedBy"),
            @Result(column = "UPDATED_DT", property = "updatedDt")
    })
    List<DbLinkPo> selectAllDataSource();
}
